Validation Xbasic

Description

Specify Xbasic code to test if the data in this field is valid.

images/vx10.png
An error message generated using Xbasic

By default, only dirty fields are validated. You can specify that all fields should be validated in Update Settings, Edit Properties. If this field is a Repeating Section, see the setting in the Repeating Section for 'Validation - field option' and 'Validation - row option'.

Using Validation Xbasic

  1. In the UX Builder on the UX Controls page open the 'Data Controls' menu. Click on the [TextBox] option to add a textbox control to the component. Give the control the name 'firstname' and the label 'First name'.

    images/vx2.png
  2. Click on the [TextBox] option again to add a second textbox control. Give this textbox the name 'lastname' and the label 'Last name'.

    images/vx3.png
  3. Highlight the lastname textbox. In the properties list on the right click the ... button next to the 'Validation rules' property in the Field Properties section.

    images/vx4.png
  4. Check the 'Enable rules' checkbox.

    images/vx5.png
  5. In the 'Text Format' section of the 'Field Validation' dialog check the 'Allow letters' and 'Allow whitespace' checkboxes. Click OK.

    images/vx6.png
  6. Click the ... button next to the 'Validation Xbasic' property.

    images/vx7.png
  7. Define the following Xbasic for the validate_lastname() function and click OK.

    function validate_lastname as p (e as p)
    
        validate_lastname.hasError = .f. ' default to no error
    
        if e.data.lastname = "Smith" then
            ' data is invalid; return an error
            validate_lastname.hasError = .t.
            validate_lastname.errorText = "Last name value can't be Smith."
        end if
    
    end function
    images/vx8.png
  8. Open the 'Defined Controls' menu and click on the 'Submit-Reset' option to add submit and reset buttons to the component.

    images/vx9.png
    When you click the submit button an Ajax callback will be made.
  9. Run the component in Live Preview. Enter 'Smith' into the Last name textbox and the Xbasic error message should fire.

    images/vx10.png

See Also